cmake_minimum_required(VERSION 3.2)
project(nne_emulator C CXX)

include(cmake/util/Util.cmake)
#include(cmake/util/FindCUDA.cmake)
#emulator_option(USE_CUDA "build with CUDA" ON)
emulator_option(HIDE_PRIVATE_SYMBOLS "Compile with -fvisibility=hidden." OFF)

include_directories("include")

if(MSVC)
    message(FATAL_ERROR "cannot build with win32 system")
else(MSVC)
  if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
    message(STATUS "Build in Debug mode")
    set(CMAKE_C_FLAGS "-O0 -g -Wall -fPIC ${CMAKE_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "-O0 -g -Wall -fPIC ${CMAKE_CXX_FLAGS}")
    set(CMAKE_CUDA_FLAGS "-O0 -g -Xcompiler=-Wall -Xcompiler=-fPIC ${CMAKE_CUDA_FLAGS}")
  else()
    set(CMAKE_C_FLAGS "-O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC ${CMAKE_CXX_FLAGS}")
    set(CMAKE_CUDA_FLAGS "-O2 -Xcompiler=-Wall -Xcompiler=-fPIC ${CMAKE_CUDA_FLAGS}")
    if (HIDE_PRIVATE_SYMBOLS)
      message(STATUS "Hide private symbols...")
      set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}")
      set(CMAKE_CXX_FLAGS "-fvisibility=hidden ${CMAKE_CXX_FLAGS}")
    endif(HIDE_PRIVATE_SYMBOLS)
  endif ()
  if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
      CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
    set(CMAKE_CXX_FLAGS "-faligned-new ${CMAKE_CXX_FLAGS}")
  endif()
endif(MSVC)

#FILE(GLOB_RECURSE GROUP_SOURCE "src/*.cc")
#FILE(GLOB_RECURSE GROUP_INCLUDE "src/*.h" "include/*.h")
#
#assign_source_group("Source" ${GROUP_SOURCE})
#assign_source_group("Include" ${GROUP_INCLUDE})

file(GLOB_RECURSE COMPILER_SRCS
    src/mem/*.cpp
    src/device/*.cpp
    src/runtime/*.cpp
    src/soc/*.cpp
    )

include(CheckCXXCompilerFlag)
if(NOT MSVC)
  check_cxx_compiler_flag("-std=c++14" SUPPORT_CXX14)
  set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
  set(CMAKE_CUDA_STANDARD 14)
else()
  message(FATAL_ERROR "cannot build with win32 system")
endif()

add_library(nne_emulator SHARED ${COMPILER_SRCS})
#add_subdirectory(examples/test_dma)
